package com.example.personalcenter;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.*;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class HomeActivity extends AppCompatActivity {

    private static final String TAG = "HomeActivity";

    /* ========== 生命周期 ========== */
    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        Log.d(TAG, "onCreate");

        String user = getIntent().getStringExtra("USER_NAME");
        Button btnLogout = findViewById(R.id.btn_logout);
        btnLogout.setOnClickListener(v -> new AlertDialog.Builder(this)
                .setTitle("提示")
                .setMessage("确认退出登录？")
                .setPositiveButton("确定", (d, w) -> {
                    // 直接finish，不finish LoginActivity，不设置FLAG
                    finish();
                })
                .setNegativeButton("取消", null)
                .show());
    }

    @Override protected void onStart() { super.onStart(); Log.d(TAG, "onStart"); }
    @Override protected void onResume() { super.onResume(); Log.d(TAG, "onResume"); }
    @Override protected void onPause() { super.onPause(); Log.d(TAG, "onPause"); }
    @Override protected void onStop() { super.onStop(); Log.d(TAG, "onStop"); }
    @Override protected void onDestroy() { super.onDestroy(); Log.d(TAG, "onDestroy"); }
    @Override protected void onRestart() { super.onRestart(); Log.d(TAG, "onRestart"); }

    /* ===== singleTask 专用 ===== */
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Log.d(TAG, "onNewIntent");
        setIntent(intent);   // 更新最新 intent
    }
}